﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TaiwuZD
{
    /// <summary>
    /// RoleCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class RoleCtrl : UserControl
    {


        public RoleCtrl()
        {
            InitializeComponent();

            //Global.Inst.CurrentRoleFeatures.CollectionChanged += CurrentRoleFeatures_CollectionChanged;

             
        }

        //private void CurrentRoleFeatures_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        //{ 
        //    if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
        //    {
        //        foreach (var item in e.NewItems)
        //        {
        //            lvTx.SelectedItems.Add(item);
        //        }
        //    }
           
        //}

        private void btnChooseMajorRole_Click(object sender, RoutedEventArgs e)
        {
            Global.Inst.CurrentRole = Global.Inst.MajorRole;
        }

        private void btnChooseOtherRole_Click(object sender, RoutedEventArgs e)
        {
            pop.IsOpen = true;
        }

       

       
        
    }


    public class FeatureColorConveter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is FeatureStar)
            {
                if (((FeatureStar)value).Color == FeatureStarColor.White)
                    return Brushes.White;

                if (((FeatureStar)value).Color == FeatureStarColor.Blue)
                    return Brushes.SkyBlue;

                if (((FeatureStar)value).Color == FeatureStarColor.None)
                    return new SolidColorBrush(Color.FromRgb(8,7,7));

                if (((FeatureStar)value).Color == FeatureStarColor.Red)
                    return Brushes.Red;
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class FeatureStarConveter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is FeatureStar)
            {
                switch ( ((FeatureStar)value).Type)
                {
                    case 0:
                        return null;
                    case  FeatureStarType.Attack:
                        return ImageSourceCache.FeatureStarsSource[0];/// new BitmapImage(new Uri("/res/fs11.png",UriKind.Relative));
                    case FeatureStarType.Defend:
                        return ImageSourceCache.FeatureStarsSource[1]; //new BitmapImage(new Uri("/res/fs22.png", UriKind.Relative));
                    case FeatureStarType.Wisdom:
                        return ImageSourceCache.FeatureStarsSource[2]; //new BitmapImage(new Uri("/res/fs33.png", UriKind.Relative));
                }
                   
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class RoleInfoAvaliableConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value != null && value is Role;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }


    public class RoleChengShuXingConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is ChengShuXing)
            switch((ChengShuXing)value)
            {
                case ChengShuXing.Early:
                    return "早熟";
                case ChengShuXing.Normal:
                    return "均衡";
                case ChengShuXing.Late:
                    return "晚成";
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }


    public class ItemTypeDispConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is TwItemType))
                return value;

            var it = (TwItemType)value;
            var attrs = it.GetType().GetField(it.ToString()).GetCustomAttributes(false);

            var des = attrs.FirstOrDefault(x => x is DescriptionAttribute) as DescriptionAttribute;
            return des?.Description;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }


    public class TwItemTypeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is TwItemType)
                return GameAssets.TwItems.Values.Where(x => x.ItemType3 == (TwItemType)value);
            else
                return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    public class TwItemType2Converter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is TwItemType)
                return Global.Inst.CurrentRole?.OwnedItems?.Where(x => x.ItemType3 == (TwItemType)value);
            else
                return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }


    public class SkillVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is Role)
            {
                if ((Role)value == Global.Inst.MajorRole)
                    return Visibility.Visible;
                else
                    return Visibility.Collapsed;
            }
            else
                return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
